// main.go
package main

import (
	"flag"
	"fmt"
	"os"

	"gitee.com/Flearning/go_crawl/mgobson"
	"gitee.com/Flearning/go_crawl/stocklist"
)

const VERSION = "1.0.2.0705"

func main() {
	data := flag.String("data", "stock", "select crawl data src: `stock, xq_user`")
	action := flag.String("action", "new", "select crawl data action: `new, up`")
	version := flag.Bool("version", true, "print App Version")

	flag.Parse()
	cmdArgs := os.Args
	if len(cmdArgs) == 1 {
		flag.PrintDefaults()
		os.Exit(2)
	}

	var cmdData, cmdAction string
	cmdData = *data
	cmdAction = *action

	// 初始化mongodb
	mgobson.NewInit()

	if cmdData == "stock" {
		switch cmdAction {
		case "new":
			exeCmdStr(cmdData, cmdAction)
			i, e := stocklist.CrawlData()
			fmt.Println(i, e)
		case "up":
			exeCmdStr(cmdData, cmdAction)
			fmt.Println("this Action: `", cmdAction, "` non-devlep.")
		default:
			fmt.Println("select crawl data action: `new, up`")
		}

	}

	if cmdData == "xq_user" {
		switch cmdAction {
		case "new":
			exeCmdStr(cmdData, cmdAction)
			fmt.Println("this Action: `", cmdAction, "` non-devlep.")
		case "up":
			exeCmdStr(cmdData, cmdAction)
			fmt.Println("this Action: `", cmdAction, "` non-devlep.")
		default:
			fmt.Println("select crawl data action: `new, up`")
		}
	}

	if cmdData != "xq_user" && cmdData != "stock" {
		fmt.Println("select crawl data src: `stock, xq_user`")
	}

	if *version {
		fmt.Println(VERSION)
	}
}

func exeCmdStr(f, s string) {
	fmt.Println("cmd execute:", f, s)
}
